package com.hmsproject.search.bean;

import java.util.List;

import com.hmsproject.datastructures.Hotel;
import com.hmsproject.db.inmemorydb.DealMap;
import com.hmsproject.db.inmemorydb.HMSInMemoryDBConnection;
import com.hmsproject.livedata.LiveDealCriterion;
import com.hmsproject.livedata.LiveDealData;

public class HotelInfo {

	private Hotel hotel;
	private LiveDealData liveDealData;
	
	private int personCount;
	
	private int percentOff;
	
	public int getPersonCount() {
		return personCount;
	}

	public void setPersonCount(int personCount) {
		this.personCount = personCount;
	}

	public int getPercentOff() {
		return percentOff;
	}

	public void setPercentOff(int percentOff) {
		this.percentOff = percentOff;
	}

	public HotelInfo(Hotel hotel){
		this.hotel = hotel;
	}
	
	public Hotel getHotel() {
		return hotel;
	}
	
	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}
	
	public LiveDealData getLiveDealData() {
		if(this.liveDealData == null && this.hasDeal()){
			  this.liveDealData = HMSInMemoryDBConnection.getInstance().getLiveDealData(DealMap.INSTANCE.getDealForHotel(this.hotel.getHotelId()).getDealId());
			  List<LiveDealCriterion> liveDealCriterions = this.liveDealData.getLiveDealCriterions();
			  
			  if(!liveDealCriterions.isEmpty()){
				  this.personCount = liveDealCriterions.get(0).getNoOfRoomsMore();
				  this.percentOff = liveDealCriterions.get(0).getAdditionalPercentOff();
			  }
		}
		return liveDealData;
	}
	
	public void setLiveDealData(LiveDealData liveDealData) {
		this.liveDealData = liveDealData;
	}

    public boolean hasDeal(){
    	return hotel.isHasDeal();
    }
    
    public String hasDealInString(){
    	return this.hasDeal()?"true":"false";
    }
	
}
